
package DomainLayer;

import java.util.ArrayList;

/**
 * In this class ArrayLists are created, where Product type objects are stored.
 * @author Zsombi
 */
public class ProductContainer
{
    private ArrayList<Product> products = new ArrayList<Product>();

    /**
     * Constructor of ProductContainer class.
     */
    public ProductContainer()
    {   }

    /**
     * Adds an existing Product object into the products ArrayList.
     * @param product
     */
    public void addProduct(Product product)
    {
        products.add(product);
    }

    /**
     * Creates a new Product object.
     * Adds this object to the products ArrayList.
     * @param Id
     * @param Name
     * @param Amount
     * @param Price
     * @param Discount
     * @param Description
     */
    public void addProduct(String Id, String Name, int Amount, double Price, double Discount, String Description)
    {
        Product product = new Product(Id, Name, Amount, Price, Discount, Description);
    }

    /**
     * Searches for a Product object by its Name.
     * If found, delete/remove that object from the products ArrayList.
     * @param productId
     */
    public void deleteProduct(String productId)
    {
        for(int i=0; i<products.size(); i++)
        {
            if(products.get(i).getId().equals(productId))
            {
                products.remove(i);
            }
        }
    }

    /**
     * Search for a Product object by its Name.
     * If found, return its information.
     * @param productId
     * @return
     */
    public Product getProduct(String productId)
    {
        for(int i=0; i<products.size(); i++)
        {
            if(products.get(i).getId().equals(productId))
            {
                return products.get(i);
            }
        }
        return null;
    }

    /**
     * Prints out all the products contained by the products ArrayList.
     */
    public void listProducts()
    {
        for(Product product : products)
        {
            System.out.println(products + " /n");
        }
    }

    /**
     * Searches for a Product object by its Identification code (Id).
     * If found, prints out all information about it.
     * @param productId
     */
    public void listProductDetails(String productId)
    {
        for(int i=0; i<products.size(); i++)
        {
            if(products.get(i).getId().equals(productId))
            {
                System.out.println("Product ID:             " + products.get(i).getId() + "/n");
                System.out.println("Product Name:           " + products.get(i).getName() + "/n");
                System.out.println("Product Amount:         " + products.get(i).getAmount() + "/n");
                System.out.println("Product Price:          " + products.get(i).getPrice() + "/n");
                System.out.println("Product Discount:       " + products.get(i).getDiscount() + "/n");
                System.out.println("Product Description:    " + products.get(i).getDescription() + "/n");
                System.out.println("/n");
            }
        }
    }
}
